#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using D2DEngine.Scene;
using D2DEngine.Components;
using D2DEngine.Components.AI;
#endregion

namespace D2DEngine
{
    /// <summary>
    /// A drawable object of in the scene.
    /// </summary>
    ///

    public class D2DSceneObject : D2DObject
    {
        protected D2DScene scene;

        protected bool visible = true;
        protected float layer = 2.0f;
        protected Vector2 position = Vector2.Zero;
        protected float rotation = 0.0f;

        protected Rectangle boundingBox = Rectangle.Empty;


        protected D2DGraphicsComponent sprite = null;
        protected D2DWorldLimitComponent worldLimit = null;
        protected D2DMountComponent mount = null;
        protected D2DAIComponent ai = null;

        /// <summary>
        /// The scene the object is in
        /// </summary>
        public D2DScene Scene
        {
            get { return this.scene; }
            set { this.scene = value; }
        }   

        /// <summary>
        /// The visibility of the scene object
        /// </summary>
        public bool Visible
        {
            get { return this.visible; }
            set { this.visible = value; }
        }
       
        /// <summary>
        /// The layer depth of the scene object
        /// </summary>
        public float Layer
        {
            get { return this.layer; }
            set { this.layer = value; }
        } 
         

        /// <summary>
        /// The position of the scene object
        /// </summary>
        public virtual Vector2 Position
        {
            get { return this.position; }
            set { this.position = value; }
        }        

        /// <summary>
        /// The rotation angle of the object
        /// </summary>
        public virtual float Rotation
        {
            get { return this.rotation; }
            set { this.rotation = value; }
        }       


        /// <summary>
        /// Bouding box of the object
        /// </summary>
        public Rectangle BoundingBox
        {
            get { return this.boundingBox; }
            set { this.boundingBox = value; }
        }
        

        /// <summary>
        /// Creates a new scene object
        /// </summary>
        public D2DSceneObject() 
        {
        }

        /// <summary>
        /// Code to execute when the object is
        /// registered to a scene.
        /// </summary>
        public override void OnRegister()
        {
            base.OnRegister();
        }

        /// <summary>
        /// Moves the scene object
        /// </summary>
        /// <param name="velocity">The velocity</param>
        public virtual void Move(Vector2 velocity)
        {
            Position += velocity;
        }




        /// <summary>
        /// The graphic representation of the scene object
        /// </summary>
        public D2DGraphicsComponent Sprite
        {
            get
            {
                if (this.sprite != null) { return this.sprite; }
                else { this.sprite = GetComponent<D2DGraphicsComponent>(); return this.sprite; }
                   
            }
            set { this.sprite = value; }
        }

        /// <summary>
        /// The artificial intelligence of the scene object
        /// </summary>
        public D2DAIComponent AI
        {            
            get
            {
                if (this.ai != null) { return this.ai; }
                else { this.ai = GetComponent<D2DAIComponent>(); return this.ai; }
            }
            set { this.ai = value; }
        }

        /// <summary>
        /// The world limit component of the scene object
        /// </summary>
        public D2DWorldLimitComponent WorldLimit
        {
            get
            {
                if (this.worldLimit != null) { return this.worldLimit; }
                else { this.worldLimit = GetComponent<D2DWorldLimitComponent>(); return this.worldLimit; }
            }
            set { this.worldLimit = value; }
        }


        /// <summary>
        /// The artificial intelligence of the scene object
        /// </summary>
        public D2DMountComponent Mount
        {
            get
            {
                if (this.mount != null) { return this.mount; }
                else { this.mount = GetComponent<D2DMountComponent>(); return this.mount; }
            }
            set { this.mount = value; }
        }

        /// <summary>
        /// Copies the scene object
        /// </summary>
        /// <param name="obj"></param>
        protected override void CopyTo(D2DObject obj)
        {
            D2DSceneObject sceneObj = (D2DSceneObject)obj;
            sceneObj.Visible = this.visible;
            sceneObj.Position = Position;
            sceneObj.Rotation = this.rotation;
            sceneObj.Layer = this.layer;

            base.CopyTo(obj);
        }
    }
     
}
